import { Component, Vue } from 'vue-property-decorator'
import { Action } from 'vuex-class'
import styles from './index.less'

@Component({})
export default class HandWriteView extends Vue {
  @Action('applyPage/submitSealElectronicPic') submitSealElectronicPic!: any

  removeBase64Header(base64: string) {
    const identifier = 'base64,'

    return base64.split(identifier)[1]
  }

  render() {
    return (
      <draw-signature-pad
        onGetBase64={this.handleBase64}
        class={styles.handWriteView}
      />
    )
  }
  async handleBase64(base64: string) {
    try {
      await this.submitSealElectronicPic({
        taskId: this.$route.query.taskId,
        picB64: this.removeBase64Header(base64),
      })
      this.$router.push({
        name: 'resultPage',
        query: {
          success: 'true',
        },
      })
    } catch (e) {
      this.$router.push({
        name: 'resultPage',
        query: {
          success: 'false',
          message: e,
        },
      })
    }
  }
}
